<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        #clock-box {
            /* 父元素宽度依靠子内容撑开 */
            /* display:linne-block  -> 改变元素性质 */
            width: fit-content;
            margin: 0 auto;
            text-align: center;
            padding: 10px;
        }

        #clock-box #clock-time {
            font-size: 40px;
            line-height: 50px;
            font-family: "clockIcon";
        }

        @font-face {
            font-family: "clockIcon";
            src: url('../font/clockicons.woff2');
        }
    </style>
</head>

<body>
    <div id="clock-box">
        <div id="clock-Tips">现在时间是</div>
        <div id="clock-time">00:00:00</div>
        <div id="clock-date">xxxx年xx月xx日</div>
    </div>
</body>
<script>

    var clockTime = document.getElementById("clock-time");
    var clockDate = document.getElementById("clock-date");

    // 页面加载时 执行一次
    showTime();
    setInterval(showTime,1000);



    function showTime() {
        var date = new Date();

        var year = date.getFullYear();
        var month = date.getMonth() + 1;
        var day = date.getDate();

        var hour = date.getHours();
        var minute = date.getMinutes();
        var second = date.getSeconds();

        clockTime.innerHTML = `${beauty(hour)}:${beauty(minute)}:${beauty(second)}`;
        clockDate.innerHTML = `${year}年${beauty(month)}月${beauty(day)}日`;

    }
    function beauty(num) {
        return num < 10 ? "0" + num : num;
    }







</script>

</html>